package com.gexiaobao.pigeon.ui.fragment.setting.address

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.gexiaobao.pigeon.app.base.BaseActivity
import com.gexiaobao.pigeon.app.model.bean.ProvinceEntity
import com.gexiaobao.pigeon.databinding.ActivityPickAddressBinding
import com.gexiaobao.pigeon.ui.adapter.ContactAdapter
import com.gexiaobao.pigeon.viewmodel.SettingViewModel
import com.github.promeg.pinyinhelper.Pinyin
import com.github.promeg.tinypinyin.lexicons.android.cncity.CnCityDict
import me.yokeyword.indexablerv.IndexableLayout

/**
 * @Author      : hxw
 * @Date        : 2024/4/17 15:41
 * @Describe    :
 */
class ActivityPickAddress : BaseActivity<SettingViewModel, ActivityPickAddressBinding>() {

    private lateinit var mAdapter: ContactAdapter
    private var infoList = ArrayList<ProvinceEntity>()

    override fun initView(savedInstanceState: Bundle?) {
        infoList = intent?.getSerializableExtra("list") as ArrayList<ProvinceEntity>

        initAdapter()
    }

    private fun initAdapter() {
        mDatabind.indexLayout.setLayoutManager(LinearLayoutManager(this))
        // 多音字处理
        Pinyin.init(Pinyin.newConfig().with(CnCityDict.getInstance(this)))
        mAdapter = ContactAdapter(this)
        mDatabind.indexLayout.setAdapter(mAdapter)
        mDatabind.indexLayout.setOverlayStyle_Center()
        mAdapter.setDatas(infoList)
        //全字母排序。  排序规则设置为：每个字母都会进行比较排序；速度较慢
        mDatabind.indexLayout.setCompareMode(IndexableLayout.MODE_FAST)
    }
}